package com.log;
import java.io.*;

/**
 * https://blog.csdn.net/qq_46452300/article/details/126029613
 */
public class RootCommand {
    public static void execCommand(String cmd1, String cmd2) {
        try {
            Runtime runtime = Runtime.getRuntime();
            // 打开任务管理器，exec方法调用后返回 Process 进程对象
            // 怎样以管理员权限调用cmd? <以管理员权限打开eclipse>
            Process process0 = runtime.exec("cmd.exe /c wevtutil qe "+ cmd1 +" /f:text /rd:true > E:\\eclipse\\CurriculumDesign\\src\\log\\" + cmd2);
//            Process process1 = runtime.exec("cmd.exe /c wevtutil qe Security /f:text /rd:true > C:\\Users\\22147\\Desktop\\Security_Log.txt");
//            Process process2 = runtime.exec("cmd.exe /c wevtutil qe Application /f:text /rd:true > E:\\eclipse\\CurriculumDesign\\src\\log\\Application_Log.txt");
//            Process process3 = runtime.exec("cmd.exe /c wevtutil qe System /f:text /rd:true > C:\\Users\\22147\\Desktop\\System_Log.txt");
//            Process process4 = runtime.exec("cmd.exe /c wevtutil qe Setup /f:text /rd:true > C:\\Users\\22147\\Desktop\\Setup_Log.txt");
//            Process process5 = runtime.exec("cmd.exe /c wevtutil qe ForwardedEvents /f:text /rd:true > C:\\Users\\22147\\Desktop\\ForwardedEvents_Log.txt");
            // 等待进程对象执行完成，并返回“退出值”，0 为正常，其他为异常
            int exitValue0 = process0.waitFor();
//            int exitValue1 = process1.waitFor();
//            int exitValue2 = process2.waitFor();
//            int exitValue3 = process3.waitFor();
//            int exitValue4 = process4.waitFor();
//            int exitValue5 = process5.waitFor();
            System.out.println("日志输出: " + exitValue0);
//            System.out.println("exitValue1: " + exitValue1);
//            System.out.println("exitValue2: " + exitValue2);
//            System.out.println("exitValue3: " + exitValue3);
//            System.out.println("exitValue4: " + exitValue4);
//            System.out.println("exitValue5: " + exitValue5);
            // 销毁process对象
            process0.destroy();
//            process1.destroy();
//            process2.destroy();
//            process3.destroy();
//            process4.destroy();
//            process5.destroy();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
//    public static void main(String[] args) {
//        execCommand();
//    }
}
